<style lang="scss">
.form {
  margin: 20px 40px 20px 20px;
}
</style>

<template>
  <div class="form">
    <el-form ref="form" :model="renderData" label-width="120px">
      <el-form-item label="校验秘钥">
        <el-input v-model="renderData.secret" style="width:300px;"></el-input>
      </el-form-item>

      <el-form-item label="项目所在文件夹">
        <el-input v-model="renderData.file" style="width:300px;"></el-input>
      </el-form-item>

      <el-form-item label="CMD命令">
        <el-input v-model="renderData.cmd" style="width:300px;"></el-input>
      </el-form-item>

      <el-form-item label="接受请求地址">
        <el-input v-model="renderData.url" style="width:300px;"></el-input>
      </el-form-item>

      <el-form-item label="创建新项目">
        <el-switch v-model="renderData.new"></el-switch>
      </el-form-item>

      <el-form-item label="端口号">
        <el-input v-model="renderData.port" style="width:300px;"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
    <!-- /弹窗 -->
    <el-dialog title="生成代码" :visible.sync="dialogVisible" width="60%">
      <pre>{{ showData }}</pre>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">
          确 定
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import http from "axios";
export default {
  data() {
    return {
      renderData: {
        secret: "Rain",
        file: "C:\\APP\\MyWorkLoad",
        cmd: "git pull",
        url: "/MyWorkLoad",
        port: 7777,
        new: false
      },
      dialogVisible: false,
      showData: ""
    };
  },
  methods: {
    async onSubmit() {
      console.log(this.renderData);
      const r = await http.post(
        "http://localhost:3000/create",
        this.renderData
      );
      if (r.data.length > 2) {
        console.log(r);
        this.showData = r.data;
      } else {
        console.log("生成成功");
      }
      this.dialogVisible = true;
    }
  }
};
</script>
